package com.cy.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cy.jt.mapper.RightsMapper;
import com.cy.jt.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:
 * @author: LiuXingYu
 * @date: 2021/8/4 11:54
 */
@Service
public class RightsServiceImpl implements RightsService{

    @Autowired
    private RightsMapper rightsMapper;

    @Override
    public List<Rights> getRightList() {
        QueryWrapper<Rights> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", 0);
        List<Rights> oneList = rightsMapper.selectList(queryWrapper);
        for (Rights rights : oneList) {
            queryWrapper.clear();
            queryWrapper.eq("parent_id", rights.getId());
            List<Rights> children = rightsMapper.selectList(queryWrapper);
            rights.setChildren(children);
        }
        return oneList;
    }


}
